package com.chaosj.memory.handlers;

import com.chaosj.html.markdown.HTML2Md;
import com.chaosj.memory.dto.WxGzhDto;
import lombok.extern.slf4j.Slf4j;

import java.io.IOException;
import java.net.MalformedURLException;
import java.net.URL;

/**
 * @className: WxGzhHandler
 * @description:
 * @author: caoyangjie
 * @date: 2021/12/25
 **/
@Slf4j
public class WxGzhHandler extends AbstractToolHandler<WxGzhDto> {

    @Override
    public String name() {
        return "wx";
    }

    @Override
    public void handler(WxGzhDto req, StringBuffer outBuffer) {
        req.getScrapes().stream().forEach(url->{
            try {
                HTML2Md.convert(new URL(url), "utf-8", true, false);
            } catch (MalformedURLException e) {
                log.error(e.getMessage());
            } catch (IOException e) {
                log.error(e.getMessage());
            }
        });
    }

    @Override
    public WxGzhDto cmd2Dto(String[] args) {
        return new WxGzhDto(args);
    }
}
